// more.js
var app = getApp()
Page({

    /**
     * 页面的初始数据
     */
    data: {
        // text:"这是一个页面"
        index: -1,
        inde: -1,
        cat_id: 0,
        m_id: 0,
        controls: false,
        videoHidden: true,
        cates: [],
        photoadd: [],
        video_url: '',
        array: ['视频', '照片']
    },


    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function(options) {

    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    addVideo: function() {
        var that = this;
        wx.chooseVideo({
            sourceType: ['album', 'camera'],
            //录制视频最大时长
            maxDuration: 60,
            //摄像头
            camera: ['front', 'back'],
            //这里返回的是tempFilePaths并不是tempFilePath
            success: function(res) {
                wx.navigateTo({
                    url: 'morevideo/morevideo?video_url=' + res.tempFilePath
                })
            },
            fail: function(e) {
                console.log(e)
                wx.switchTab({
                    url: '../index/index'
                })
            }
        })
    },
    onShow: function() {
        // this.addVideo()
    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function() {

    },
    listenerBtnOpenImage: function() {
        var that = this;
        wx.chooseImage({
            count: 1,
            sizeType: ['compressed'],
            //sizeType: ['original','compressed'],
            sourceType: ['album'],
            success: function(res) {
                console.log('res', res)
                    // 返回选定照片的本地文件路径列表，tempFilePath可以作为img标签的src属性显示图片
                var tempFilePaths = res.tempFilePaths[0];
                // that.photoadd.push(tempFilePaths);
                // var photo = that.data.photoadd = tempFilePaths;
                console.log(tempFilePaths)
                that.setData({
                        photo: tempFilePaths
                    })
                    // app.globalData.photo_loca = photo;
            }
        })
    },

    //获取本地视频路径
    listenerBtnOpenVideo: function() {
        var that = this;
        wx.chooseVideo({
            //相机和相册
            sourceType: ['album', 'camera'],
            //录制视频最大时长
            maxDuration: 60,
            //摄像头
            camera: ['front', 'back'],
            //这里返回的是tempFilePaths并不是tempFilePath
            success: function(res) {
                that.setData({
                    video_url: res.tempFilePath,
                    videoHidden: false,
                })
            },
            fail: function(e) {
                console.log(e)
            }
        })
    },



    addFile: function() {
        var that = this;
        var session_key = wx.getStorageSync('session_key');
        console.log('wwwwww', session_key);
        wx.uploadFile({
            url: 'http://sheying.j8j0.com/api/Upload/post_video',
            method: "POST",
            filePath: that.data.photo,
            name: 'img',
            header: {
                'content-type': 'multipart/form-data'
            },
            formData: {
                session_key: session_key,
                img_url: that.data.photo
            },
            success: function(res) {
                console.log(res)
                var data = res.data
                    //do something
                console.log('ok')
            }
        })
    },
    bindaddVideo: function() {
        var that = this;
        wx.chooseVideo({
            sourceType: ['album', 'camera'],
            //录制视频最大时长
            maxDuration: 60,
            //摄像头
            camera: ['front', 'back'],
            //这里返回的是tempFilePaths并不是tempFilePath
            success: function(res) {
                that.setData({
                    video_url: res.tempFilePath,
                    videoHidden: false,
                })
                wx.navigateTo({
                    url: 'morevideo/morevideo?video_url=' + res.tempFilePath
                })
            },
            fail: function(e) {
                console.log(e)
            }
        })
    },
    bindaddPhoto: function() {
        var that = this;
        wx.chooseImage({
            count: 6,
            sizeType: ['compressed'],
            //sizeType: ['original','compressed'],
            sourceType: ['album', 'camera'],
            success: function(res) {
                console.log(res)
                    // 返回选定照片的本地文件路径列表，tempFilePath可以作为img标签的src属性显示图片
                var tempFilePaths = res.tempFilePaths;
                // that.photoadd.push(tempFilePaths);
                // var photo = that.data.photoadd = tempFilePaths;

                // app.globalData.photo_loca = photo;
                // that.setData({
                //     photoadd: photo
                // })
                wx.setStorageSync('photo_urls', tempFilePaths)
                wx.navigateTo({
                    url: 'morePhoto/morePhoto'
                })
            }
        })
    },
    bindCancel: function() {
        wx.switchTab({
            url: '../index/index'
        })
    }
})